package com.itheima.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.mapper.PmsProductCategoryMapper;
import com.itheima.pojo.db.PmsProduct;
import com.itheima.pojo.db.PmsProductCategory;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductCategoryApiImpl implements PmsProductCategoryApi {
    @Autowired
    private PmsProductCategoryMapper pmsProductCategoryMapper;

    @Override
    public Long getCatePid(PmsProduct product) {
        PmsProductCategory pmsProductCategory = pmsProductCategoryMapper.selectById(product.getProductCategoryId());
        return pmsProductCategory.getParentId();
    }

    @Override
    public PmsProductCategory selectOne(Long parentId) {
        return pmsProductCategoryMapper.selectById(parentId);
    }

    @Override
    public void insert(PmsProductCategory productCategory) {
        pmsProductCategoryMapper.insert(productCategory);
    }

    @Override
    public void delete(Long id) {
        pmsProductCategoryMapper.deleteById(id);
    }

    @Override
    public List<PmsProductCategory> selectList() {
        return pmsProductCategoryMapper.selectList(new LambdaQueryWrapper<PmsProductCategory>().eq(PmsProductCategory::getParentId, 0));
    }

    @Override
    public List<PmsProductCategory> selectByPid(Long id) {
        return pmsProductCategoryMapper.selectList(new LambdaQueryWrapper<PmsProductCategory>().eq(PmsProductCategory::getParentId, id));
    }

    @Override
    public IPage<PmsProductCategory> selectPage(IPage<PmsProductCategory> page, Long parentId) {
        return pmsProductCategoryMapper.selectPage(page, new LambdaQueryWrapper<PmsProductCategory>().eq(PmsProductCategory::getParentId, parentId));
    }

    @Override
    public int update(PmsProductCategory productCategory, List<Long> ids) {
        return pmsProductCategoryMapper.update(productCategory, new LambdaQueryWrapper<PmsProductCategory>().in(PmsProductCategory::getId, ids));
    }

    @Override
    public void updateById(PmsProductCategory productCategory) {
        pmsProductCategoryMapper.updateById(productCategory);
    }

    @Override
    public PmsProductCategory select(Long id) {
        return pmsProductCategoryMapper.selectById(id);
    }


}
